package adv9;

import java.net.*;
import java.util.*;
import java.io.*;

public class ObjectThread extends Thread {
	private Socket socket;

	public ObjectThread(Socket s) {
		this.socket = s;
	}

	@Override
	public void run() {
		System.out.println(socket + "连接了");
		Map<String, String> m = new HashMap<String, String>();
		m.put("江北第一帅哥", "陈兵");
		m.put("江南第一帅哥", "朱峰");
		m.put("肥东第一帅哥", "老刘");
		try {
			InputStream in = socket.getInputStream();
			OutputStream out = socket.getOutputStream();
			ObjectOutputStream oout = new ObjectOutputStream(out);
			ObjectInputStream oin = new ObjectInputStream(in);
			oout.writeObject(m);
			oout.flush();// 手动刷新
			Object get = oin.readObject();
			System.out.println("get from " + socket.getInetAddress() + ":"
					+ get);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			// e.printStackTrace();
		} finally {
			if (socket != null)
				try {
					socket.close();
				} catch (IOException e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
		}

	}
}
